package experiment1.closestpoints;

public class Point implements Comparable<Point>{
    public static int dimension;
    public double x;
    public double y;

    Point(double x,double y){
        this.x = x;
        this.y = y;
        dimension = 2;
    }
    Point(double x){
        this.x = x;
        dimension = 1;
    }

    @Override
    public String toString() {
        if (this.dimension == 1){
            return String.valueOf(this.x);
        }
        return "("+this.x+","+this.y+")";
    }

    public double distance(Point point) {
        switch (dimension){
            case 1:return Math.abs(this.x-point.x);
            case 2:return Math.sqrt((this.x-point.x)*(this.x-point.x)+(this.y-point.y)*(this.y-point.y));
        }
        return -1.0;
    }

    @Override
    public int compareTo(Point o) {
        return Double.compare(this.x,o.x) == 0?Double.compare(this.y,o.y):Double.compare(this.x,o.x);
    }
}
